package nu.mine.tbje.easyEDT;

import java.util.ArrayList;

public class Node {

	String name;
	int id;
	ArrayList<Node> children;
	Node parent = null;

	public Node(int id, String name){
		this.id = id;
		this.name = name;
		this.children = new ArrayList<Node>();
	}
	
	public void addChild(Node node){
		node.parent = this;
		children.add(node);
	}

	public Node getChild(int id) throws Exception {
		Node res;
		if (children.contains(new Node(id, ""))){
			int pos = children.indexOf(new Node(id, ""));
			res = children.get(pos);
		} else {
			throw new Exception();
		}
		return res;
	}

	public boolean equals(Object o){
		boolean res = false;
		try {
			if (((Node) o).id == this.id){
				res = true;
			}
		} catch (ClassCastException e) {
			// if cast fails return false
		}
		return res;
	}
	
	
	
}
